import os
import time
import tkinter as tk
from tkinter.messagebox import *
from playsound import playsound
from search_song import search_songs
from download_song import down

win = tk.Tk()


def find():
    songs_lst = search_songs(entry.get())
    down(songs_lst)
    if os.path.exists('my.mp3'):
        showinfo('下载完成！')


def play():
    while True:
        if os.path.exists('my.mp3'):
            playsound("my.mp3")
            break


win.title('音乐播放器-by王小呆')
x = (win.winfo_screenwidth()-300) // 2
y = (win.winfo_screenheight()-500) // 2
win.geometry(f"300x500+{x}+{y}")

tk.Label(win, text='\n输入歌曲名称\n').pack()
entry = tk.Entry(win)
entry.pack()

button = tk.Button(win, text='点击搜索', command=find)
button.pack(pady=10)

play_button = tk.Button(win, text='点击播放', command=play)
play_button.pack(pady=10)

win.mainloop()
